package com.example.administrator.runbook.findfragment.activity;

import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.runbook.R;
import com.example.administrator.runbook.fragments.CommonFragment;
import com.example.administrator.runbook.fragments.adapter.FragmentAdapter;
import com.example.administrator.runbook.findfragment.audiobooks.AbCityFragment;
import com.example.administrator.runbook.findfragment.audiobooks.FantasyFragment;
import com.example.administrator.runbook.findfragment.audiobooks.FrightenedFragment;
import com.example.administrator.runbook.findfragment.audiobooks.HistoryFragment;
import com.example.administrator.runbook.findfragment.audiobooks.PublishFragment;
import com.flyco.tablayout.SlidingTabLayout;


import java.util.ArrayList;
import java.util.List;

public class AudioBooksActivity extends BaseActivity implements View.OnClickListener {

    private Toolbar mToolbar;
    private TextView mTitle;
    private SlidingTabLayout mSlidingTabLayout;
    private ViewPager mViewPager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_audio_books);

        initView();

        if (mToolbar != null) {
            mTitle.setText("有声小说");
            setSupportActionBar(mToolbar);
        }

        List<CommonFragment> fragmentList = new ArrayList<>();
        fragmentList.add(new AbCityFragment());
        fragmentList.add(new FantasyFragment());
        fragmentList.add(new FrightenedFragment());
        fragmentList.add(new HistoryFragment());
        fragmentList.add(new PublishFragment());
        FragmentAdapter fragmentAdapter = new FragmentAdapter(
                getSupportFragmentManager(),
                fragmentList
        );
        mViewPager.setAdapter(fragmentAdapter);
        mViewPager.setOffscreenPageLimit(fragmentList.size());
        mSlidingTabLayout.setViewPager(mViewPager);
    }

    private void initView() {
        mToolbar = (Toolbar) findViewById(R.id.activity_find_classify_toolbar);
        mTitle = (TextView) findViewById(R.id.find_toolbar_text_title);
        mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.audio_books_tab);
        mViewPager = (ViewPager) findViewById(R.id.audio_books_fragment_container);
    }

    @Override
    public void setBackImg(ImageView backImg) {
        if (backImg != null) {
            backImg.setOnClickListener(this);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.activity_find_classify_goBack_img:
                finish();
                break;
        }
    }
}
